package com.ea.controller.back;

import com.ea.api.controller.admin.OrderEvaluateApi;
import com.ea.common.enums.OperationResultCode;
import com.ea.common.exception.ServiceException;
import com.ea.common.response.JsonResult;
import com.ea.domain.dto.StoreEvaluateDTO;
import com.ea.domain.query.EvaluateQueryDTO;
import com.ea.domain.vo.OrderDetailVO;
import com.ea.domain.vo.StoreEvaluateVO;
import com.ea.service.IStoreEvaluateInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 留言信息表 前端控制器
 * </p>
 *
 * @author 电器商城
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/electric/evaluate")
public class OrderEvaluateController implements OrderEvaluateApi {

    @Autowired
    private IStoreEvaluateInfoService evaluateInfoService;

    @Override
    @PostMapping("/list")
    public JsonResult getOrderEvaluateList(@RequestBody EvaluateQueryDTO queryDTO) {
        PageInfo<StoreEvaluateVO> evaluateList = evaluateInfoService.getEvaluateList(queryDTO);
        return JsonResult.doSuccessful(evaluateList);
    }

    @Override
    @GetMapping("/goods")
    public JsonResult getOrderEvaluate(@RequestParam("goodsId") Long goodsId) {
        if (goodsId == null) {
            throw new ServiceException(OperationResultCode.PARAMETER_ERROR);
        }
        List<OrderDetailVO> orderDetailVOS = evaluateInfoService.listCanEvaluateGoods(goodsId);
        return JsonResult.doSuccessful(orderDetailVOS);
    }


    @PostMapping("/insert")
    public JsonResult insertEvaluate(@RequestBody StoreEvaluateDTO evaluateDTO){
        evaluateInfoService.evaluateGoodsBySkuId(evaluateDTO);
        return JsonResult.doSuccessful();
    }

}
